﻿using mds.NoSqlDatabase;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace mds.DistributedRelay
{
    public class DistributedRelayProvider:ICache
    {
        private static DistributedRelayProvider _instance = new DistributedRelayProvider();

        public static DistributedRelayProvider Instance
        {
            get { return _instance; }
           
        }
        private RedisProvider _clientRedis;
      
        private DistributedRelayProvider()
        {
            _clientRedis = new RedisProvider();
        }
        public T Get<T>(string key) where T : class, ISystemCache, new()
        {
            var config=CacheConfigService.Instance.GetConnection();
            return _clientRedis.Get<T>(key, config.Host, config.Port);
        }
        public BaseFrameModel.OperationResult<bool> Add<T>(String key,T data) where T : class, ISystemCache, new()
        {
            var config = CacheConfigService.Instance.GetConnection();
            return _clientRedis.Save<String,T>(key,data, config.Host, config.Port);
        }
        public BaseFrameModel.OperationResult<bool> Store<T>(T data) where T : class, ISystemCache, new()
        {
            var config = CacheConfigService.Instance.GetConnection();
            return _clientRedis.Save<T>(data, config.Host, config.Port);
        }

        public BaseFrameModel.OperationResult<bool> Delete(string key)
        {
            var config = CacheConfigService.Instance.GetConnection();
            return _clientRedis.Delete(key, config.Host, config.Port);
        }

        public BaseFrameModel.OperationResult<bool> Deletes(List<string> keys)
        {
            var config = CacheConfigService.Instance.GetConnection();
            return _clientRedis.Deletes(keys, config.Host, config.Port);
        }

        public Dictionary<string, T> Gets<T>(List<string> keys) where T : class, ISystemCache, new()
        {
            var config = CacheConfigService.Instance.GetConnection();
            return _clientRedis.Gets<T>(keys, config.Host, config.Port);
        }
    }
}
